function initmap(){
    var url = 'http://support.supermap.com.cn:8090';
        
    var China = L.supermap.tiledMapLayer(url + '/iserver/services/map-china400/rest/maps/China');
    var ChinaDark = L.supermap.tiledMapLayer(url + '/iserver/services/map-china400/rest/maps/ChinaDark');
    // , {noWrap:true})
    var map = L.map('map', {   
        center: [29.618493015610223,106.6510945558548],
        maxZoom: 18,
        zoom: 8,
        zoomControl: false,
        // 设置图层数组
        layers: [China]
    });
    var Position = {};

    var baseMaps = { "China": China, "ChinaDark": ChinaDark };
    // 添加图层切换控件
    L.control.layers(baseMaps).addTo(map);
    // 比例尺
    L.control.scale().addTo(map);
    // L.marker([25, 102]).addTo(map).bindPopup("<b>中国</b><br>安徽黄山.").openPopup();
    // 缩放
    L.control.zoom().addTo(map).setPosition('topright');
    // 测距
    L.Control.measureControl().addTo(map).setPosition('topright');
    
    // 定位
    function locationClick(coordinate){
        map.setCenter(fromLonLat(coordinate));
    }

    // 飞机数据接口：http://dkjs.op-fly.cn/map/map/plane  以json数据传参
    // 172.18.132.134:10007/map/plane
    var pointArr=[]
    getData();
    

    var get_time_id;


    function getData(){
        
        $.ajax({
            url: "http://dkjs.op-fly.cn/map/map/plane",
            type: "POST",
            data: JSON.stringify(post_air_json()),
            headers:{"Content-Type":"application/json"},
            dataType: "json",
            success:function(res){  
                let nums = map.getZoom();
                
                airMarker(res.cat021Infos,nums);
               
                get_time_id = setInterval(function(){
                   getData();
                },2000);
            },
            error:function(res){
                
            }
        })
    }
    
    function post_air_json(){
        var json = {
            "lng":"106.65109455585481",
            "lat": "29.618493015610223",
            "range": "1500"
        }
        return json
    }

    var geojsonMarkerOptions = {
        radius:8,
        fillColor:'#ff7800',
        color:"#000",
        weight:1,
        opacity:1,
        fillOpacity:0.8
    };

    var Icon = L.Icon.extend({
        options: {  
            iconSize: [76, 76], //图标的大小  
            iconAnchor: [0, 0], //点图标将对应标记的位置  
            popupAnchor: [25, 15], //点弹出打开相对于iconanchor  
        }  
    });
    
    // 飞机图标
    var myLayerGroup = new L.LayerGroup();
    // 标牌信息
    var mydivCroup = new L.LayerGroup();
   
    var airMar,divhtml,planePoint;
    function airMarker(res,zoomindex){
        // 批量清除所有标记
        myLayerGroup.clearLayers();
        mydivCroup.clearLayers();
        pointArr =[];
   
        for(var i =0;i<res.length;i++){
            // 标牌信息
            let divIhtml,imghtml,imgIcon,divI;
            if(zoomindex >= 10){
                divIhtml = scutcheon(res[i]);
                imgIcon = new Icon({
                    iconUrl : 'images/plane_big.png'
                })
                mydivCroup.addLayer(divhtml);
               
            }else if(zoomindex >= 7 && zoomindex <10){

                imgIcon = new Icon({
                    iconUrl : 'images/plane_zhong.png',
                    iconSize:[38,38]
                })
                
            }else{

                imgIcon = new Icon({
                    iconUrl : 'images/plane_small.png',
                    iconSize:[19,19]
                })
            }
            
            // 提示详细信息
            let innerHTML = bindHtml(res[i]);
            
            divI = L.divIcon({
                html:divIhtml,
                className:'my-div-icon'
            })

            var ImgI = L.divIcon({
                html:imghtml
            }) 
            
            let lat = res[i].cat021Bean.lat,//经度
            log = res[i].cat021Bean.log,// 维度
            heading = res[i].cat021Bean.heading;//航向
            
            let int_heading = Math.round(heading);
            if(int_heading >=0 && int_heading <=30 || int_heading >330 && int_heading <=360){
                divI = L.divIcon({
                    html:divIhtml,
                    className:'class_icon_1'
                })
                
            }else if(int_heading >30 && int_heading <= 90){
                divI = L.divIcon({
                    html:divIhtml,
                    className:'class_icon_2'
                })
            
            }else if(int_heading >90 && int_heading <= 150){
                divI = L.divIcon({
                    html:divIhtml,
                    className:'class_icon_3'
                })
            
            }else if(int_heading >150 && int_heading <= 210){
                divI = L.divIcon({
                    html:divIhtml,
                    className:'class_icon_4'
                })
                
            }else if(int_heading >210 && int_heading <= 270){
                divI = L.divIcon({
                    html:divIhtml,
                    className:'class_icon_5'
                })
                
            }else if(int_heading >270 && int_heading <= 330){
                divI = L.divIcon({
                    html:divIhtml,
                    className:'class_icon_6'
                })
                
            }
            
            

            Position.lat = lat;
            Position.log = log;

            pointArr.push([lat,log])
            // 创建飞机图标 批量生成marker
            airMar = L.marker([lat,log],{icon:imgIcon,rotationAngle:heading}).on('click', function(e) {
                map.setView([lat,log],12);
                imgIcon = new Icon({
                    iconUrl : 'images/plane_big_pitch.png',
                    iconSize:[76,76]
                })
                // map.removeLayer(airMar);
                // airMar = L.marker([lat,log])
                // airMar.setIcon(imgIcon)
              });
            divhtml = L.marker([lat,log],{icon:divI})
            
            // 给marker进行分组
            myLayerGroup.addLayer(airMar); 

        } 
        map.addLayer(mydivCroup);
        map.addLayer(myLayerGroup); 
        clearInterval(get_time_id);
      
    }
    
    function bindHtml(res){
        var innerHTML = "";
        innerHTML += "S模式地址："+res.cat021Bean.targetAddress+"<br>";
        innerHTML += "SSR："+res.cat021Bean.mode3A+"<br>";
        innerHTML += "FID："+res.cat021Bean.targetIden+"<br>";
        innerHTML += "数据来源："+res.cat021Bean.identification+"<br>";
        innerHTML += "经度："+res.cat021Bean.log+"<br>";
        innerHTML += "维度："+res.cat021Bean.lat+"<br>";
        innerHTML += "高度："+res.cat021Bean.flyHeight+"<br>";
        innerHTML += "地速："+res.cat021Bean.groundSpeed+"<br>";
        innerHTML += "更新时间："+res.cat021Bean.payloadTime+"<br>";

        return innerHTML
    }

    function scutcheon(res){
        var divIhtml = "<div>";
        // divIhtml += "<img src='"+imgurl+"' alt=''>";
        // divIhtml += "<span>"+Math.round(res.cat021Bean.heading)+"</span><br>";
        divIhtml += "<span>"+res.cat021Bean.targetAddress+"</span><br>";
        divIhtml += "<span>"+res.cat021Bean.targetIden+"</span><br>";
        divIhtml += "<span>"+Math.round(res.cat021Bean.flyHeight*100)/100+" "+Math.round(res.cat021Bean.verticalSpeed*100)/100+"</span><br>";
        divIhtml += "<span>"+Math.round(res.cat021Bean.flyHeight*100)/100+"</span>";
        divIhtml += "<span>"+res.cat021Bean.aircraftType+"</span></div>";

        return divIhtml
    }

    return {map:map,Position:Position}
}

